/**
 * Copyright 2011 By Shayne, Zhang.
 * 
 * The contents of this file are developped by Shayne, Zhang. You may visit:
 * http://www.shaynez.com for more details.
 *
 */
package com.shaynez.ec.element;

import com.shaynez.ec.Constants;
import com.shaynez.ec.exception.InvalidateValueException;

/**
 * This is aperture class. 
 * 
 * 
 * 
 * @author shayne zhang
 * 
 */
public class Aperture implements Calculatable<Aperture>, ExposureElement {

	/** The aperture value. */
	private double value;
	

	
	/**
	 * Create a aperture instance. 
	 * 
	 * @param value
	 * @return
	 * @throws InvalidateValueException
	 */
	public static Aperture getInstance(double value) throws InvalidateValueException{
		if(value < Constants.THE_MIN_APERTURE_VALUE || value > Constants.THE_MAX_APERTURE_VALUE){
			throw new InvalidateValueException("Invalidate aperture value > " + value);
		}
		return new Aperture(value);
	}
	
	protected Aperture(double value){
		this.value = value;
	}
	
	@Override
	public double getValue(){
		return value;
	}
	
	@Override
	public double getExposureValue(){
		return this.value * this.value;
	}
	
	@Override
	public double getValueByExposureValue(double exposureValue) {
		// TODO Auto-generated method stub
		return java.lang.Math.sqrt(exposureValue);
	}

	@Override
	public Factor compare(Aperture o) {
		// TODO Auto-generated method stub
		return new Factor(o.getExposureValue() / this.getExposureValue());
	}

	@Override
	public Aperture calculate(Factor factor) throws InvalidateValueException {
		// TODO Auto-generated method stub
		return Aperture.getInstance(this.getValueByExposureValue(this.getExposureValue() / factor.getValue()));
	}


	
	
}
